package main.java.com.lee.juc;

import main.java.com.lee.Util;

import java.util.concurrent.locks.LockSupport;

/**
 * @Description TODO
 * @Author winston
 * @DateTime 2022/1/18
 */
public class LockSupportDemo {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(new parkWorker(), "t1");
        Thread t2 = new Thread(new parkWorker(), "t2");

        t1.start();

        Thread.sleep(1000);

        t2.start();

        t1.interrupt();

        LockSupport.unpark(t2);
    }


    static class parkWorker implements Runnable {
        @Override
        public void run() {
            Util.print(Thread.currentThread().getName() + " 即将调用LockSupport.park方法, 然后进入无限等待");
            LockSupport.park();
            if (Thread.currentThread().isInterrupted()) {
                Util.print(Thread.currentThread().getName() + " 被中断了, 继续执行");
            } else {
                Util.print(Thread.currentThread().getName() + " 被唤醒了, 继续执行");

            }
        }
    }
}
